<?php

namespace app\common\service;

use GatewayWorker\Lib\Gateway;

class WsEventService
{
    //连接
    public static function onConnect($client_id)
    {
        echo "[$client_id]连接上啦\n";
        Gateway::sendToClient($client_id,"Your client_id is $client_id");
    }
    //接收消息
    public static function onMessage($client_id, $data)
    {
        echo "接收[$client_id]的消息: $data\n";
        if ($data !== 'ping') {
            Gateway::sendToClient($client_id, "client_id: $client_id ->"."data => $data");
        }
    }
    public static function onClose($client_id)
    {
        echo "[$client_id]关闭连接\n";
        //Gateway::closeClient($client_id);
    }
    public static function onWorkerStart($businessWorker)
    {
        //print_r($businessWorker);
        echo "id:$businessWorker->id\n";
        echo "workerId:$businessWorker->workerId\n";
        echo "status:$businessWorker->status\n";
        //Gateway::sendToCurrentClient("WorkerStart");
        //Gateway::sendToClient($businessWorker, "client_id: $businessWorker");
    }
    public static function onWorkerStop($businessWorker)
    {
        //Gateway::sendToCurrentClient("WorkerStop");
    }
    public static function onWorkerReload($businessWorker)
    {
        //Gateway::sendToCurrentClient("WorkerReload");
    }
}
